package com.example.demo.service.bis.impl;

import com.example.demo.bean.bis.Picture;
import com.example.demo.repository.PictureMapper;
import com.example.demo.service.bis.PictureService;
import com.example.demo.service.exception.ErrorCode;
import com.example.demo.service.exception.ServiceException;
import com.example.demo.utils.ConstantUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author zzz
 * @Title: PictureServiceImpl
 * @ProjectName test
 * @Description: TODO()
 * @date 2018/7/12
 */
@Service
@Transactional
public class PictureServiceImpl implements PictureService {

    @Autowired
    private PictureMapper pictureMapper;

    @Value("${IMG.URL.SUFIX}")
    private String imgUrl;
    @Override
    @Scheduled(cron = "0 30 23  * * ?")
    public List<Picture> findAll() {
        return null;
    }

    @Override
    public List<Picture> findByUid(Integer uId) {
        if (StringUtils.isEmpty(uId)){
            throw new ServiceException(ErrorCode.NULL_ERROR);
        }
        List<Picture> list = pictureMapper.findByUid(uId);
        if (!StringUtils.isEmpty(list) && list.size()>ConstantUtils.SUCCEED){
            for (int i = ConstantUtils.SUCCEED;i<list.size();i++){
                list.get(i).setPictureMin(imgUrl+list.get(i).getPicture());
            }
        }
        return list;
    }

}
